package com.itheima.ThreadPrac6;

import java.util.ArrayList;
import java.util.Collections;

public class mythread6 extends Thread{

    ArrayList<Integer> list=new ArrayList<>();

    public mythread6(ArrayList<Integer> list) {
        this.list = list;
    }

    @Override
    public void run() {
        ArrayList<Integer> boxlist=new ArrayList<>();
        double SUM=0;
        while (true)
        {
            synchronized (mythread6.class)
            {
                if(list.size()==0)
                {//还要获取该集合内的最高奖项,以及输出总金额
                    int maxnum =Collections.max(boxlist);
                    System.out.println(getName()+boxlist+",其中最高的金额为"+maxnum+"总金额为"+SUM+"元。");
                    break;
                }else
                {
                    Collections.shuffle(list);
                    Integer prize = list.remove(0);
                    SUM+=prize;
                    boxlist.add(prize);
                }
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
